/**
 *
 */
package org.suren.littlebird.console;

import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;
import org.suren.littlebird.server.ClientInfo;
import org.suren.littlebird.server.LogServerListener;

/**
 * @author suren
 * @since 2015-2-12
 */
public class LogListener implements LogServerListener
{
	private MessageConsoleStream msgStream;

	public LogListener()
	{
		MessageConsole logConsole = LogConsoleFactory.getConsole();
		this.msgStream = logConsole.newMessageStream();
		msgStream.setActivateOnWrite(true);
		logConsole.addPatternMatchListener(new SuRenPatternMatchListener());
	}

	@Override
	public void onLine(ClientInfo clientInfo)
	{
	}

	@Override
	public void offLine(ClientInfo clientInfo)
	{
	}

	@Override
	public synchronized void printMessage(CharSequence msg)
	{
		String msgStr = msg.toString();
		msgStream.print(msgStr);
	}

}
